package com.obor.quartz.job;

import java.io.Serializable;
import java.util.Date;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import org.springframework.format.annotation.DateTimeFormat;
import org.zn.mvcbase.common.utilities.JacksonDateSerializer;
import org.zn.mvcbase.mybatis.Examplee;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.obor.mybatis.handler.MapTypeHandler;

import tk.mybatis.mapper.annotation.ColumnType;
@Table(name = "job_info")
public class JobInfo implements Serializable {

	private static final long serialVersionUID = 1L;
	
	public static final String TYPE_MS="ms";
	public static final String TYPE_API="api";
	public static final String TYPE_CLASS="class";
	
	public JobInfo() {}
	
	public JobInfo(String id,String data) {
		this.id = id;
		this.dataStatus = data;
	}

	@GeneratedValue(strategy = GenerationType.IDENTITY)
    @Id
    @Column(name = "ID")
	private String id;

	
	/**
	 * 任务名称
	 */
	@Column(name = "`name`")
	@Examplee(condition = "like", prefix = "%", suffix = "%")
	private String name;
	
	/**
	 * 任务key名
	 */
	@Column(name = "`key`")
	@Examplee(condition = "like", prefix = "%", suffix = "%")
	private String key;

	
	/**
	 * 任务描述
	 */
	@Column(name = "description")
	@Examplee(condition = "like", prefix = "%", suffix = "%")
	private String description;

	/**
	 * 触发条件
	 */
	@Column(name = "cron_expression")
	@Examplee(condition = "like", prefix = "%", suffix = "%")
	private String cronExpression;

	/**
	 * 任务所属组
	 */
	@Column(name = "`group`")
	@Examplee
	private String group;

	/**
	 * 任务当前状态
	 */
	@Column(name = "`status`")
	@Examplee
	private String status;

	/**
	 * 所属服务类型
	 */
	@Column(name = "type")
	@Examplee
	// [inner Service class ,outter service api,mico service]
	private String type;

	/**
	 * 全限定类名
	 */
	@Column(name = "bean_class")
	@Examplee(condition = "like", prefix = "%", suffix = "%")
	private String beanClass;

	/**
	 * 微服务名称
	 */
	@Column(name = "ms_name")
	@Examplee(condition = "like", prefix = "%", suffix = "%")
	private String msName;

	/**
	 * 服务url地址
	 */
	@Column(name = "api_url")
	private String apiUrl;

	/**
	 * 方法名
	 */
	@Column(name = "method")
	@Examplee(condition = "like", prefix = "%", suffix = "%")
	private String method;

	@Column(name = "parameters")
	@ColumnType(typeHandler = MapTypeHandler.class)
	private Map<String, Object> parameters;

	/**
	 * 创建人
	 */
	@Column(name = "create_user")
	@Examplee(condition = "like", prefix = "%", suffix = "%")
	private String createUser;

	/**
	 * 创建时间
	 */
	@Column(name = "create_time")
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	@JsonSerialize( using = JacksonDateSerializer.class)
	private Date createTime;
	
	@Column(name = "update_time")
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	@JsonSerialize( using = JacksonDateSerializer.class)
	private Date updateTime;
	
	@Examplee
	@Column(name = "data_status")
	private String dataStatus;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getCronExpression() {
		return cronExpression;
	}

	public void setCronExpression(String cronExpression) {
		this.cronExpression = cronExpression;
	}

	public String getBeanClass() {
		return beanClass;
	}

	public void setBeanClass(String beanClass) {
		this.beanClass = beanClass;
	}

	public String getApiUrl() {
		return apiUrl;
	}

	public void setApiUrl(String apiUrl) {
		this.apiUrl = apiUrl;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getGroup() {
		return group;
	}

	public void setGroup(String group) {
		this.group = group;
	}

	public String getCreateUser() {
		return createUser;
	}

	public void setCreateUser(String createUser) {
		this.createUser = createUser;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getMsName() {
		return msName;
	}

	public void setMsName(String msName) {
		this.msName = msName;
	}

	public String getMethod() {
		return method;
	}

	public void setMethod(String method) {
		this.method = method;
	}

	public Map<String,Object> getParameters() {
		
//		Gson gson = new Gson();
//		Map<String,Object> map = new HashMap<String, Object>();
//		return gson.fromJson(parameters, map.getClass());
		return parameters;
	}

	public void setParameters(Map<String,Object> parameters) {
//		if(StringUtils.isNoneBlank(parameters)) {
//			Gson gson = new Gson();
//			parameters = gson.fromJson(parameters, parameters.getClass());
//		}
		
		this.parameters = parameters;
	}

	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	/**
	 * @return the dataStatus
	 */
	public String getDataStatus() {
		return dataStatus;
	}

	/**
	 * @param dataStatus the dataStatus to set
	 */
	public void setDataStatus(String dataStatus) {
		this.dataStatus = dataStatus;
	}

}